
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="base" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>设备管理</title>
  <link href="${base}/assets/css/public.css" rel="stylesheet">
  <link href="${base}/assets/css/list.css" rel="stylesheet">
  <script src="${base}/assets/js/jquery.min.js"></script>
  <link rel="stylesheet" type="text/css" href="${base}/assets/css/jquery.searchableSelect.css" />
  <script type="text/javascript" src="${base}/assets/js/jquery.searchableSelect.js"></script> 
  <style>
	#pageshow{
		height:40px;
		padding-left: 30%;
	}
	#pageshow a{
		float:left;
		    text-decoration: none;
		font-family: consolas;
	}
	#pagenum{
		float:left;
	}
</style> 
</head>
<body>
<input type="hidden" id="pageNo" value="${pageNo}"/>
<div class="top">
<c:import url="../commons/top.jsp"/>
</div>
<div class="wrap">

  <div class="side">
	<c:import url="../commons/sidebar.jsp"/>
  </div>
  <div class="cont">
    <div class="bread">
      <span>设备管理</span><span>&nbsp;&gt;&nbsp;</span><span>excel导入预览</span>
      <div class="excel-add">
        <a class="add" href="javascript:void(0)" onclick="fahui()">返回</a>
      </div>
      
      <script type="text/javascript">
		function fahui(){
			var url ="${base}/back/devicelist.do";
			window.location.href=url;
		}
      </script>
      <div class="clear"></div>
    </div>
    <div class="cate">
          <ul>
              <li>
                  <span>所属分类:</span>
                  <select  id="cid" name="cid">
	                   <option value="">--请选择--</option>
	                    <c:forEach items="${maxc}" var="m">
	                    	<option value="${m.id}" <c:if test="${cid==m.id}">selected="selected"</c:if>>${m.name}</option>
	                    </c:forEach>
	              </select>
              </li>
              <li id="fciddiv">
                  <span>功能分类:</span>
                  <select  id="fcid" name="fcid" >
	                  <option value="">--请选择--</option>
	                       <c:forEach items="${midc}" var="mi">
	                           <option value="${mi.id}" <c:if test="${fcid==mi.id}">selected="selected"</c:if>>${mi.name}</option>
	                       </c:forEach>
	                  </select>
          </ul>
    </div>
    <table id="sample_editable_1" width="100%" border="1" cellspacing="0" cellpadding="0" bordercolor="#e9e9f0" class="list">
      <thead>
        <tr style="background-color:#ccc;">
            <th>设备分类 </th> 
            <th>品       牌 </th> 
            <th>旧  编 号 </th>
            <th>编       号</th>
            <th>型       号</th>
            <th>出厂编号</th>
            <th>投产年月</th>
            <th>折旧年限</th>
            <th>采购价格(元)</th> 
            <th>当前位置</th>
            <th>状       态</th>
            <th>备       注</th>
            <th><input id="allselect" type="checkbox" value="" />全选</th>
         </tr>
      </thead>
      <tbody>
         <c:forEach items="${tempd}" var="tep" varStatus="status">
               <tr style="background-color:rgba(226, 223, 223);">
               <td>${tep.dn}</td>
	           <td>${tep.brand}</td>
	           <td>${tep.oldno}</td>
	           <td>${tep.no}</td>
	           <td>${tep.xhno}</td>
	           <td>${tep.ccno}</td>
	           <td>${tep.tcrq}</td>
	           <td>${tep.zjnx}</td>
	           <td>${tep.cgjg}</td>
	           <c:if test="${tep.wnis =='1'}">
                    <td>${tep.wn}</td>
               </c:if>
               <c:if test="${tep.wnis=='2'}">
                   <td ><font color="red">${tep.wn}</font></td>
               </c:if>
	           <td>${tep.status}</td>
	           <td><a href="#" title="${tep.remark}">${ fn:substring(tep.remark,0,3)}</a></td> 
	           <td><input type="checkbox" value="${tep.id}"/></td>       
               </tr>
          </c:forEach> 
     </tbody>
    </table>
    <div class="excel-add" style=" withd:100%;text-align:center;">
       <a onclick="submitInputExcel()" class="add" >提交</a>
	</div>
  </div>
  
  <div class="clear"></div>
</div>
</body>
</html>

<link rel="stylesheet" type="text/css" href="${base}/assets/css/jquery.searchableSelect.css" /> 
 <script type="text/javascript" src="${base}/assets/js/jquery.searchableSelect.js"></script> 
<script type="text/javascript">
var selectarr= new Array();
 $(function(){
	$('#cid').searchableSelect({  
        afterSelectItem: function(){  
           var fsv= this.holder.data("value");
           if(fsv!=null && fsv!=''){
            	$.ajax({
					url: '${base}/back/searchmidc.do?pid='+fsv,
					async:false,
					dataType:"json",
					type:"post",
					success:function (data){
						$('#fciddiv').html("");
						var list = data.midc;
						if(list.length>0){
							var sel = '<label class=" control-label">部门分类:</label><select id="fcid" name="fcid" ><option value=""></option>'
							$.each(list,function(index,item){
								 sel +='<option value=" '+item.id+'">'+item.name+
									'</option>';
							});
							sel += '</select>';
							$('#fciddiv').append(sel);
							fcidcaozuo();
						}else{
							var sel = '<label class=" control-label">部门分类:</label><select id="fcid" name="fcid" ><option value="">无子分类</option></select>';
							$('#fciddiv').append(sel);
							$('#fcid').searchableSelect();
						} 	
					},
				});
            }
        }	 
    });
	$('#fcid').searchableSelect();
	function fcidcaozuo(){
		$('#fcid').searchableSelect({  
	     /*    afterSelectItem: function(){  
	            var fsv= this.holder.data("value");
	            if(fsv!=null && fsv!=''){
	             	$.ajax({
	 					url: '${base}/back/searchmidc.do?pid='+fsv,
	 					async:false,
	 					dataType:"json",
	 					type:"post",
	 					success:function (data){
	 						$('#dciddiv').html("");
	 						var list = data.midc;
	 						if(list.length>0){
								var sel = '<label class=" control-label">设备分类:</label><select id="dcid" name="dcid" ><option value=""></option>'
								$.each(list,function(index,item){
									 sel +='<option value=" '+
											item.id + '">'+item.name+
										'</option>';
								});
								sel += '</select>';
								$('#dciddiv').append(sel);
								$('#dcid').searchableSelect();
							}else{
								var sel = '<label class=" control-label">设备分类:</label><select id="fcid" name="fcid" ><option value="">无子分类</option></select>';
								$('#dciddiv').append(sel);
								$('#dcid').searchableSelect();
							} 
						}, 
	 				});
	             }	
	         }  */ 
	     });
	}
 });
   function submitInputExcel(){

	   var cid =  $.trim($("#cid").val());
	   var fcid = $.trim($("#fcid").val());
	   var dcid = $("#fcid").val();
	   if(cid==null || cid==''){
		   alert("请选择分类");
		   return;
	   }
	   if(fcid==null || fcid==''){
		   alert("请部门分类");
		   return;
	   }
	   if(selectarr.length<=0){
		   alert("请选择要上传的设备！！");
		   return;
	   }
       $.ajax({
           type: "POST",
           url: '${base}/back/submitInputExcel.do',
           dataType: "json", // 数据格式:JSON
           data:{"cid":cid,"fcid":fcid,"dcid":dcid,"sarr[]":selectarr},
           success: function (data) {
        	   if(data.ok=='ok'){
        		   alert("添加成功！！");
	        	   $('input:checkbox').each(function(){
	        		    var isin = false;
		   		   		for(var sa in selectarr){
		   		   			if(selectarr[sa]==this.value){
		   		   				isin = true;
		   		   				break;
		   		   			}
		   		   		}
		   		   		if(isin){
		   		   		  this.disabled=true;
		   		   		  this.value=null;
		   		   		}
		   		   			
		 		 });  
	        	 selectarr.splice(0,selectarr.length); 
        	  }
           },
       });
   }
   $('input:checkbox').click(function () {
	   if(this.id=="allselect"){
		   selectarr.splice(0,selectarr.length);
		   if(this.checked){ 
			   $('input:checkbox').each(function(){
				  
			      if(this.value != null && this.value !=""){
			    	  this.checked=true;
			    	  selectarr.push(this.value);
			      }
			    });
		   }else{
			   $('input:checkbox').each(function(){
				   selectarr.splice(0,selectarr.length);
			      if(this.value != null && this.value !=""){
			    	  this.checked=false;
			      }
			    });
		   }
	   }else{
		   if(this.checked){
		   		var isin = true;
		   		for(var sa in selectarr){
		   			if(selectarr[sa]==this.value){
		   				isin = false;
		   				break;
		   			}
		   		}
		   		if(isin)
		   			selectarr.push(this.value);
		   }else{
			   var isin=null;
		   		for(var sa in selectarr){
		   			if(selectarr[sa]==this.value){
		   				isin = sa;
		   				break;
		   			}
		   		}
		   		if(isin !=null)
		   			selectarr.splice(isin,1);
		   }
	   }
 }); 

</script>
  